from django.urls import include, path
from rest_framework.authtoken.views import obtain_auth_token

from user import views
from rest_framework.routers import SimpleRouter, DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token

# 自动生成路由方法, 必须使用视图集
# router = SimpleRouter()  # 没有根路由  /user/ 无法识别
router = DefaultRouter()   # 有根路由
router.register(r'user', views.UserViewSet)
router.register(r'role', views.RoleViewSet)

urlpatterns = [
    path('register/', views.RegisterView.as_view()),  # 注册视图,  /user/register/
    path('login/', obtain_jwt_token),     # 获取token，登录视图
    path('refresh/', refresh_jwt_token),  # 刷新token
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),  # 认证地址
]

urlpatterns += router.urls  # 模块地址
# print(router.urls)

# obtain_jwt_token = ObtainJSONWebToken.as_view()      # 获取token
# refresh_jwt_token = RefreshJSONWebToken.as_view()    # 刷新token
# verify_jwt_token = VerifyJSONWebToken.as_view()      # 修改token